﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head><link rel="stylesheet" href="${ctx}/common/common.css">
    <title>Title</title>
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all">
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>
    
    <script src="${ctx}/common/plugins/jquery-1.10.2.min.js"></script>
</head>
<body>
<form class="layui-form" action="${ctx}/appUpload/saveAppUpload" method="post" enctype="multipart/form-data" >
    <input type="hidden" name="id" value="${appUpdate.id}"/>
    <div class="layui-form-item layui-col-md5" style="margin-top: 50px">
        <label class="layui-form-label">版本号<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="uploadVersion" value="${appUpdate.uploadVersion}"   lay-verify="required"  class="layui-input"  />
        </div>
    </div>
    <div class="layui-form-item  layui-col-md5">
        <label class="layui-form-label">是否整包更新<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="radio" lay-filter="isWholePackage" id="isWholePackageYes" name="isWholePackage" ${appUpdate.isWholePackage eq '0'?'checked':''} value="0" title="是">
            <input type="radio" lay-filter="isWholePackage"  ${empty appUpdate.isWholePackage?"checked":"" }  name="isWholePackage" ${appUpdate.isWholePackage eq '1'?'checked':''} value="1" title="否">
        </div>
    </div>
    <div class="layui-form-item  layui-col-md5" ${appUpdate.isWholePackage ne "0"?"style='display: none'":'' } id="iphoneUploadUrl">
        <label class="layui-form-label">苹果整包更新地址<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="iphoneUploadUrl" value="${appUpdate.iphoneUploadUrl}" class="layui-input"  />
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">上传更新文件<span style="color: red">*</span></label>
        <div class="layui-input-block" id="uploadFile">
            <button type="button" class="layui-btn" id="test1" >
                <i class="layui-icon">&#xe67c;</i>上传wgt文件
            </button>
            <c:if test="${!empty appUpdate.uploadUrl && fn:length(appUpdate.uploadUrl)>0  && appUpdate.uploadUrl != 'null' }">
                <a id="oldFile" href="${ctx}${appUpdate.uploadUrl}"  download="${ctx}${appUpdate.uploadUrl}" >${appUpdate.uploadUrl}</a>
            </c:if>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="formBtn" lay-submit lay-filter="formDemo">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/html" id="radioTpl">
    <input type="radio" name="sex"   value="{{d.id}}" data-personName="{{d.name}}" lay-filter="radiodemo">
</script>
<script>

    //Demo
    var form = null;
    var uploadInst;
    var $;
    layui.use('form', function () {
         $ = layui.$;
        form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            var aCount=$("#oldFile").length;
            if(aCount<=0){
                layer.alert("请选择更新文件!");
                return false;
            }

            layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            return true;
        });
        form.on('radio(isWholePackage)', function(data){
            if(data.value=="0"){
                $("#iphoneUploadUrl").show();
                $("input[name='iphoneUploadUrl']").attr("lay-verify","required")
                $("input[name='iphoneUploadUrl']").val("")
                $("#test1").html('<i class="layui-icon">&#xe67c;</i>上传apk文件');
                uploadInst.config.exts='apk';//核心语句！！！
                $("#oldFile").remove()
            }else{
                $("#iphoneUploadUrl").hide();
                $("input[name='iphoneUploadUrl']").attr("lay-verify","")
                $("input[name='iphoneUploadUrl']").val("")
                $("#test1").html('<i class="layui-icon">&#xe67c;</i>上传wgt文件');
                uploadInst.config.exts='wgt';//核心语句！！！
                $("#oldFile").remove()
            }
        });
        if('${appUpdate.isWholePackage}' == "0"){
            document.getElementById("iphoneUploadUrl").style.display="block"
            $("#test1").html('<i class="layui-icon">&#xe67c;</i>上传apk文件');
        }
    });
    var fileType='wgt'
    if('${appUpdate.isWholePackage}' == "0"){
        fileType='apk'
    }
   layui.use('upload', function(){
        var $ = layui.$;
        var upload = layui.upload;
        var count=0;
        //执行实例
         uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,field:'file'
            ,multiple:false
            ,auto:false
            ,exts:fileType
            ,choose:function(obj){
                var files = obj.pushFile();
                obj.preview(function(index, file, result) {
                    $("#oldFile").remove();
                    $("#uploadFile").append('<a id="oldFile" >'+file.name+'</a>');
                })
            }
        });
    });



</script>
</body>
</html>



